package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @Classname: Demo11
 * @Author: bromide
 * @CreateTime: 2022/5/10--14:24
 * @Version: V1.0
 * @Description:
 */
public class Demo11 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String username = scanner.nextLine();
        System.out.print("请输入密码:");
        String password = scanner.nextLine();
        try(Connection conn = DBUtils.getConn()) {
            PreparedStatement ps = conn.prepareStatement("select password from user where username=?");
            ps.setString(1,username);
            ResultSet set = ps.executeQuery();
            if (set.next()){
                if (password.equals(set.getString(1))){
                    System.out.println("登录成功!");
                }else {
                    System.out.println("密码错误!");
                }
            }else {
                System.out.println("用户名不存在!");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
